<template>
  <div class="user-card">
    <a-avatar :size="64" class="ava-box">{{ nickname }}</a-avatar>
    <p class="userfullname">{{ userFullname }}</p>
    <a-space :size="34" class="info">
      <span class="info-item">
        <icon-tag />
        <span class="info-text">{{ isAdmin }}</span>
      </span>
      <span class="info-item">
        <icon-phone />
        <span class="info-text">{{ phone }}</span>
      </span>
      <span class="info-item">
        <icon-email />
        <span class="info-text">{{ email }}</span>
      </span>
    </a-space>
  </div>
</template>

<script lang="ts" setup>
  import { computed } from 'vue';
  import { useUserStore } from '@/store';

  const userStore = useUserStore();

  const userFullname = computed(() => {
    return userStore.name || '';
  });

  const nickname = computed(() => {
    return userFullname.value.substring(0, 1);
  });

  const phone = computed(() => {
    return userStore.phone || '';
  });

  const email = computed(() => {
    return userStore.email || '';
  });

  const isAdmin = computed(() => {
    if (userStore.admin === 1) {
      return '超级管理员';
    }
    if (userStore.admin === 0) {
      return '管理员';
    }
    return '普通成员';
  });
</script>

<style scoped lang="less">
  .user-card {
    margin-top: 24px;
    background: url('@/assets/images/profile-bg.png') no-repeat;
    display: flex;
    align-items: center;
    flex-direction: column;
  }
  .ava-box {
    margin-top: 34px;
  }
  .userfullname {
    margin: 8px 0 0;
    font-size: 16px;
    line-height: 24px;
    color: var(--color-text-1);
  }
  .info {
    margin: 8px 0 36px;
    &-text {
      margin-left: 4px;
      font-size: 14px;
      color: var(--color-text-1);
      line-height: 22px;
    }
  }
</style>
